﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace PhotoBook.Repositorio
{
    public class RepositorioTemplate : RepositorioBase, PhotoBook.Model.NHibernate.IRepositorioTemplate 
    {
        #region IGenericRepository<Template> Members

        public int Count()
        {
            throw new NotImplementedException();
        }

        public void Delete(PhotoBook.Model.Entities.Template obj)
        {
            using (ISession session = this.SessionNHiBernate.OpenSession())
            {
                session.Delete(obj);
            }  
        }

        public int Insert(PhotoBook.Model.Entities.Template obj)
        {
            using (ISession session = this.SessionNHiBernate.OpenSession())
            {
                return (int)session.Save(obj);
            }  
        }

        public IList<PhotoBook.Model.Entities.Template> Select()
        {
            using (ISession session = this.SessionNHiBernate.OpenSession())
            {
                ICriteria criteria = session.CreateCriteria(typeof(PhotoBook.Model.Entities.Template));
                return criteria.List<PhotoBook.Model.Entities.Template>();
            } 
        }

        public PhotoBook.Model.Entities.Template SelectById(object id)
        {
            using (ISession session = this.SessionNHiBernate.OpenSession())
            {
                return session.Get<PhotoBook.Model.Entities.Template>(id);
            }
        }

        public void Update(PhotoBook.Model.Entities.Template obj)
        {
            using (ISession session = this.SessionNHiBernate.OpenSession())
            {
                session.Update(obj);
            } 
        }

        #endregion
    }
}
